#!/usr/bin/env php
<?php
/**
 * Yii console bootstrap file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/albertwxy/yii2-swoole/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');
require(__DIR__ . '/common/config/defined.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/apis/config/main.php'), require(__DIR__ . '/apis/config/main-local.php')
);

// 关闭Yii2自己实现的异常错误
defined('YII_ENABLE_ERROR_HANDLER') || define('YII_ENABLE_ERROR_HANDLER', false);
Yii::$container = new \yii\swoole\Container();
\yii\swoole\base\Startup::StartUp($config);
global $argv;
array_shift($argv);
$method = array_shift($argv);
$method = substr($method, strpos($method, '/') + 1);
//缓存RPC列表
Yii::$rpcList = \yii\swoole\rpc\LocalServices::getServices();
Yii::$apis = \yii\swoole\rpc\LocalServices::getApis();
call_user_func_array(['\yii\swoole\commands\SwooleCommand', $method], $argv);

//$config = yii\helpers\ArrayHelper::merge(
//    require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main-local.php')
//);
//
//$application = new \yii\swoole\console\Application($config);
//Yii::$rpcList = \yii\swoole\rpc\LocalServices::getServices();
//$exitCode = $application->run();
//exit($exitCode);
